<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>

    <th:block th:include="include :: header('新增订单管理')" />
    <th:block th:include="include :: bootstrap-editable-css" />

</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <div class="col-sm-12 search-collapse hidden">
        <form id="formId">
            <div class="select-list">
                <ul>
                    <li>
                        <label>合同名称：</label>
                        <input type="text" name="orderNo"/>
                    </li>
                    <li>
                        <label>合同编号：</label>
                        <input type="text" name="productId"/>
                    </li>
                    <li>
                        <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                        <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                    </li>
                </ul>
            </div>
        </form>
    </div>

    <form class="form-horizontal m" id="form-mallOrder-add">
        <h4 class="form-header h4">订单管理信息</h4>
        <input name="contractId" th:value="${contractId}"  id="contractId" type="hidden">
        <input name="orderType" th:value="${contractType}"  id="orderType" type="hidden">
        <input name="supplierId" th:value="${supplierId}"  id="supplierId" type="hidden">
        <div class="form-group hidden">
            <label class="col-sm-3 control-label">供应商ID：</label>
            <div class="col-sm-8">
                <input name="supplierId" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group hidden">
            <label class="col-sm-3 control-label">供应商ID：</label>
            <div class="col-sm-8">
                <input name="supplierId" class="form-control" type="text">
            </div>
        </div>
<!--        <div class="form-group hidden">-->
<!--            <label class="col-sm-3 control-label">订单类型：</label>-->
<!--            <div class="col-sm-8">-->
<!--                <div class="radio-box" th:each="dict : ${@dict.getType('b_order_type')}">-->
<!--                    <input type="radio" th:id="${'orderType_' + dict.dictCode}" name="orderType" th:value="${dict.dictValue}" th:checked="${dict.default}">-->
<!--                    <label th:for="${'orderType_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>-->
<!--                </div>-->
<!--            </div>-->
<!--        </div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">收货人姓名：</label>
            <div class="col-sm-8">
                <input name="receiptName" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">收货人电话：</label>
            <div class="col-sm-8">
                <input name="receiptPhone" class="form-control" type="text">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">收货详细地址：</label>
            <div class="col-sm-8">
                <input name="receiptAddress" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <textarea name="remark" class="form-control"></textarea>
            </div>
        </div>
    </form>
    <h4 class="form-header h4">订单详情信息</h4>
    <div class="row">
        <div class="col-sm-12">
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>

<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-table-editable-js" />

<script th:inline="javascript">
    var prefix = ctx + "order/order"

    var contractId=$("#contractId").val();
    var contractType=[[${contractType}]];

    $("#form-mallOrder-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            var data = $("#" + table.options.id).bootstrapTable('getData');
            data=JSON.stringify(data);

            var datas=$('#form-mallOrder-add').serialize()+"&params[operationNum]="+data+"&params[contractType]="+contractType;
            $.operate.save(prefix + "/add", datas);
        }
    }
    $(function() {
        var options = {
            data: [[${list}]],
            onEditableSave: onEditableSave,
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            columns: [
                {
                    field: 'cartId',
                    title: 'ID',
                    visible: false
                },
                {
                    field: 'productId',
                    title: '产品ID',
                    visible: false
                },
                {
                    field: 'name',
                    title: '产品名称',
                },
                {
                    field: 'img',
                    title: '产品图片',
                    visible: false,
                    formatter: function(value, row, index) {
                        return $.table.imageView(value);
                    }
                },
                {
                    field: 'price',
                    title: '价格'
                },
                {
                    field: 'num',
                    title: '合同总数量'
                },

                {
                    field: 'remainNum',
                    title: '合同剩余数量',
                },
                {
                    field: 'useNum',
                    title: '合同已提货数量',
                },

                {
                    field : 'operationNum',
                    title : '本次提货',
                    editable : {
                        type : 'text',
                        title : '本次提货',
                    }
                },
            ]
        };
        $.table.init(options);
    });

    function onEditableSave (field, row, rowIndex, oldValue, $el) {
        if(Number(row[field])>Number(row.remainNum)){
            $.modal.alertWarning("本次提货"+row[field]+"不能大于剩余数量"+row.remainNum+"！");
            row[field]=row.remainNum;
            return false;
        }
        // alert("字段名：" + field + "，当前值：" + row[field]  + "，旧值：" + oldValue);
    }
</script>
</body>
</html>
